package com.xk.springboot.controller;

import com.xk.springboot.pojo.Member;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

/**
 * @author:Teacher黄
 * @date:Created at 2020/04/10
 */
@Controller
@RequestMapping("/login")
public class LoginController {


    private String memberName = "admin";
    private String memberPwd = "123123";

    /**
     * 登陆页面
     * @return
     */
    @GetMapping("/page")
    public String page(){
        return "login";
    }


    /**
     * 登陆的操作
     * @param member
     * @return
     */
    @PostMapping("/do")
    public String loginDo(Member member, HttpServletRequest request){

        // 判断用户名和密码是否正确
        if(memberName.equals(member.getMemberName()) && memberPwd.equals(member.getMemberPwd())){
            // 登陆成功=> 重定向到主页
            // 保存用户状态 => 将member对象保存到session
            request.getSession().setAttribute("member",member);
            return "redirect:/index";
        }
        return "redirect:/login/page";
    }



}
